<%@ page contentType="text/html;charset=UTF-8" language="java" %> <%@ page isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>

<div id="page-content">
    <div class="row">

        <div class="col-lg-12">
            <div class="panel">
                <div class="panel-heading">
                    <h3 class="panel-title">资质管理 - 已失效</h3>
                </div>
                <div class="panel-body">

                    <div class="table-responsive">
                        <table id="cert_notvalid_table"></table>
                        <div id="cert_notvalid_page"></div>
                    </div>
                </div>
            </div>
        </div>

    </div>
</div>

<script>

    $(function(){

        init_grid_cert();

    });

    function init_grid_cert() {

        __init_jqgrid('cert_notvalid_table', 'cert_notvalid_page',
                '<%=path%>/activiti/cert/list',
                ['资质类别', '资质名称', '证书/资质号', '评定日期','有效期限', '操作', 'id'],
                [
                    {name: 'certType', index: 'certType', width: 40, sortable: false, search: false, formatter: certTypeFormat},
                    {name: 'name', index: 'name', width: 100, sortable: false, stype: 'text', searchoptions: {sopt: ['cn']}},
                    {name: 'certNo', index: 'certNo', width: 80, sortable: false, search: false},
                    {name: 'datEvaluate', index: 'datEvaluate', width: 80, sortable: false, search: false, formatter: dateOnlyFormat},
                    {name: 'datValid', index: 'datValid', width: 80, sortable: false, search: false, formatter: dateOnlyFormat},
                    {name: 'act', index: 'act', width: 250, fixed: true, sortable: false, search: false, formatter: actFormat},
                    {name: 'id', index: 'id', width: 100, key: true, hidden: true, hidedlg: true}
                ],
                true,
                {
                    postData: {catalog: 0x03}
                }
        );

    }

    function dateOnlyFormat(cellvalue, options, rowObject){
        return cellvalue.split(" ")[0];
    }

    function certTypeFormat(cellvalue, options, rowObject){
        if(rowObject.certType == 1){
            cellvalue = "企业证照";
        } else if(rowObject.certType == 2){
            cellvalue = "企业资质";
        }
        return cellvalue;
    }

    function actFormat(cellvalue, options, rowObject){
        var id = rowObject.id;
        cellvalue = '<button class="btn btn-white btn-sm" data-original-title="查看" onclick="fn_cert_read(\'' + id + '\');"><i class="fa fa-eye"> </i> 查看</button>';
        cellvalue += '<button class="btn btn-white btn-sm" data-original-title="查看" onclick="fn_cert_continue(\'' + id + '\');"><i class="fa fa-pencil-square-o"> </i> 资质延续</button>';
        return cellvalue;
    }

    function fn_cert_read(id) {
        loadURL('<%=path%>/activiti/cert/read/'+id, $('#page-content'));
    }

    function fn_cert_continue(id) {
        var url = '<%=path%>/activiti/cert/continue/'+id;
        __open_dialog_form('资质延续', url, function (dialogRef) {
            var callback = function (data) {
                if (data) {
                    dialogRef.close();

                    // 刷新jqgrid
                    $("#cert_notvalid_table").trigger("reloadGrid");;
                } else {
                    dialogRef.enableButtons();
                }
            };
            if (fn_cert_continue_save(callback) === false) {
                dialogRef.enableButtons();
            }
        });
    }
</script>